<template>
	<view class="wrap">
			<u-form class="form" :model="user">
				<u-gap height="20" bg-color="#f5f5f5"></u-gap>
				<u-form-item label="当日体温情况" label-width="180" prop="tempRep">
					<u-input type="text" v-model="user.tempRep"/>
				</u-form-item>
				<u-form-item label="当日健康码颜色" label-width="180">
					<u-input v-model="user.healthColor" :type="type" :border="border" placeholder="请选择" @click="show2=true"/>
					<u-action-sheet :list="healthColorList" v-model="show2" @click="actionSheetCallback1"></u-action-sheet>
				</u-form-item>
				<u-form-item label="身体是否健康" label-width="180">
					<u-input v-model="user.isHealthy"  placeholder="请选择" :type="type" :border="border" @click="show3=true"/>
					<u-action-sheet :list="healthList" v-model="show3" @click="actionSheetCallback2"></u-action-sheet>
				</u-form-item>
				<u-form-item label="是否为危险人群" label-width="180">
					<u-input placeholder="请选择" :type="type" :border="border" @click="show4=true" v-model="user.isDanger" />
					<u-action-sheet :list="dangerList" v-model="show4" @click="actionSheetCallback3"></u-action-sheet>
				</u-form-item>
			</u-form>
			<u-form-item label="当前位置" label-width="180" prop="nowAddress">
				<u-input type="text" v-model="user.nowAddress"/>
				<button size="mini" type="warn" @click="getCurrentAddress()">获取当前的位置</button>
				<button size="mini" type="success" @click="getAddress()">获取选择的位置</button>
			</u-form-item>
			</u-form>
			<view class="form-footer">
				<u-button class="btn" type="primary" @click="submit">提交</u-button>
				<u-button class="btn" type="default" @click="cancel">关闭</u-button>
			</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
			user:{
				tempRep:'',
				healthColor:'',
				isHealthy:'',
				isDanger:'',
				nowAddress:''
			},
			type: 'select',
			show1: false,
			show2: false,
			show3: false,
			show4: false,
			border: false,
			healthColorList:[{value:'0',text:"绿码"},{value:'1',text:"黄码"},{value:'2',text:"红码"}],
			healthList:[{value:'0',text:"健康"},{value:'1',text:"异常"}],
			dangerList:[{value:'0',text:"正常"},{value:'1',text:"危险"}],
			}
		},
		onReady() {
			this.$store.dispatch('getCity');
		},
		
		computed:{
			newCity(){
				return this.$store.state.city
			}
		},
		methods:{
			cancel(){
				uni.navigateBack();
			},
			submit(){
				this.$u.api.user.signUser(
				this.user
					).then(res => {
					if(res.code == '200'){
						uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel: false,
							success: function () {
								uni.navigateBack();
							}
						});
					}else{
						uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel: false
						});
					}
				});
			},
			getAddress(){
				let that=this;
				uni.chooseLocation({
					success:function(res){
						that.user.nowAddress=res.name+'('+res.address+')'
					}
				});
			},
			getCurrentAddress(){
				// console.log(this.newCity);
				this.user.nowAddress=this.newCity;
			},
			actionSheetCallback1(index){
				this.user.healthColor=this.healthColorList[index].text;
			},
			actionSheetCallback2(index){
				this.user.isHealthy=this.healthList[index].text;
			},
			actionSheetCallback3(index){
				this.user.isDanger=this.dangerList[index].text;
			}
		},
	}
</script>

<style lang="scss" scope>
	.title {
		display: flex;
		margin: 30rpx 0 10px;
		font-size: 50rpx;
	}
	.version {
		margin-bottom: 10rpx;
		font-size: 40rpx;
	}
	.copyright {
		margin-top: 50rpx;
		text-align: center;
		line-height: 60rpx;
		color: #999;
	}
	.cade-box{
		uni-image{
			width: 120px;
			height:120px;
			border: 1px solid #dcdcdc;
			padding: 5px;
			background: #ffffff;
		}
	}
	.cade-text{
		color: #999999;
		font-size:12px;
	}
</style>